
#pragma once
#include "ShaderVertex.h"

class ShaderVertexData
{
public:
	class VertexAttrib
	{
		PROPERTY(GLuint, m_uSize, VertexSize);
		PROPERTY(GLuint, m_uIndex, VertexIndex);
	};
	typedef std::shared_ptr<VertexAttrib> VertexAttribPtr;

public:
	void pushVertexAttrib(GLuint vertexSize, GLuint vertexIndex = 0)
	{
		if (vertexSize == 0)	return;
		auto vPtr = std::make_shared<VertexAttrib>();
		vPtr->setVertexSize(vertexSize);
		vPtr->setVertexIndex(vertexIndex);
		m_vec.push_back(vPtr);
	}
public:
	PROPERTY(GLvoid *, m_data, Data);
	PROPERTY(GLsizeiptr, m_size, DataSize);
	PROPERTY(GLuint, m_vertexSize, VertexSize);
	PROPERTY_READONLY_BY_REF(std::vector<VertexAttribPtr>, m_vec, VertexAttrib);
};

#define CREATE_SHADER_VERTEX_DATA(varName, dataset)\
	auto varName = std::make_shared<ShaderVertexData>(); \
	varName->setData((GLvoid *)dataset); \
	varName->setDataSize((GLsizeiptr)sizeof(dataset)); 

typedef std::shared_ptr<ShaderVertexData> ShaderVertexDataPtr;

class ShaderBuffer : public ShaderVertex
{
public:
	ShaderBuffer(ShaderVertexDataPtr pVertexData);
	virtual ~ShaderBuffer() = default;

public:
	virtual void initBinding();
	virtual void cleanBinding();

public:
	virtual void draw(GLuint vertexSize, GLuint vertexIndex = 0);

private:
	GLuint m_vbo;
	ShaderVertexDataPtr m_pVertexData;

public:
	static ShaderVertexPtr create(ShaderVertexDataPtr pVertexData)
	{
		auto shader = std::make_shared<ShaderBuffer>(pVertexData);
		shader->init();
		return shader->isValid() ? shader : nullptr;
	}
};